export default class Local_Window_QuestCategories extends Window_QuestCategories {
    constructor(...list) {
        super(...list)
        this._windowCursorSprite.opacity = 0;
        // 新增背景
        this._backgroundSprite = new Sprite();
        this._backgroundSprite.bitmap =
            ImageManager.loadBitmap('img/system/UI/', 'MenuBg_Category');
        this.addChildAt(this._backgroundSprite, 0);
        this._backgroundSprite.x = this.standardPadding() - 9;
        this._backgroundSprite.y = this.standardPadding() - 7;
        this.opacity = 0;
    }

    maxCols() {
        return 3
    }

    windowWidth() {
        return 400
    }

    windowHeight() {
        return this.fittingHeight(1);
    }

    defaultTextColorCode() {
        return 0
    }

    selectTextColorCode() {
        return 6
    }

    drawColorItem(index, colorCode = 0) {
        const rect = this.itemRectForText(index);
        const align = this.itemTextAlign();
        this.changeTextColor(this.textColor(colorCode)) // 使用自定义颜色，而不是使用黑色

        this.changePaintOpacity(this.isCommandEnabled(index));
        this.drawText(this.commandName(index), rect.x, rect.y, rect.width, align);
    }

    drawAllItems() {
        const curIndex = this.index()

        var topIndex = this.topIndex();
        for (let i = 0; i < this.maxPageItems(); i++) {
            const index = topIndex + i;
            if (index < this.maxItems()) {
                const colorCode = index === curIndex ? this.selectTextColorCode() : this.defaultTextColorCode()
                this.drawColorItem(index, colorCode);
            }
        }
    }

    updateAllItems() {
        if (this.contents) {
            this.contents.clear()
            this.drawAllItems()
        }
    }

    processOk() {
    }
/*
    setItemWindow(itemWindow) {
        super.setItemWindow(itemWindow)
        //this.select(0);【饕2023：似乎没用，但对商店界面有影响】

    };
    */
    setListWindow(win) {
        this._listWindow = win;
        this.select(0);
    };

    select(index) {
        super.select(index)
        this.updateAllItems() // 选择时更新字体颜色
        if (this._listWindow){
           //category窗口的_currentExt刷新（update中最后一步）在select之后，
           //需在此事先setExt一下，否则无法随select根据category所选类别刷新列表。
            //this._listWindow.setExt(this.currentExt());
            this._listWindow.setCategoryType(this.currentExt());
            this._listWindow.refresh();
            this._listWindow.select(0)
        }
    }
    activate() {
        this.active = true;
    };
    deactivate() {
        this.active = false;
    };
    
}